import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

import { getCategoryList, getBannerListApi, getFloorListApi } from '@/api/index'

// 对外暴露Store类的实例
export default ({
  namespaced: true,
  state: {
    // 三级菜单数据
    categoryList: [],
    // 轮播图数据
    bannerList: [],
    // 楼层数据
    floorList: []
  },
  mutations: {
    setCategoryList (state, categoryList) {
      state.categoryList = categoryList
    },
    setBannerList (state, bannerList) {
      state.bannerList = bannerList
    },
    setFloorList (state, floorList) {
      state.floorList = floorList
    }
  },
  actions: {
    async getCategoryList ({ commit }) {
      const res = await getCategoryList()
      // console.log(res)
      commit('setCategoryList', res.data)
    },
    async getBannerList ({ commit }) {
      const { data } = await getBannerListApi()
      // console.log(data)
      commit('setBannerList', data)
    },
    async getFloorList ({ commit }) {
      const { data } = await getFloorListApi()
      // console.log(data)
      commit('setFloorList', data)
    }
  },
  getters: {}
})
